Improve k8s canonical DNS lookup#138
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## 8.0/edge #138 +/- ##
===========================================
Coverage ? 59.91%
===========================================
Files ? 34
Lines ? 6364
Branches ? 1069
===========================================
Hits ? 3813
Misses ? 2233
Partials ? 318 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d67481a to
3112e57
Compare
Replace getfqdn-based k8s hostname resolution with a canonical-name lookup built on getaddrinfo(AI_CANONNAME). Handle resolver failures, keep the trailing dot returned by DNS, and update the Kubernetes unit tests for the charm, provider, upgrade, and utility helpers. Fixes canonical#137 Signed-off-by: Guillaume Boutry <guillaume.boutry@canonical.com>
3112e57 to
647d6c1
Compare
|
Thank you @gboutry . We'll nudge the CI so that the s390x builds are retried and the integration tests are triggered. I see you added new unit tests 👍🏼 Any chance to validate whether this PR fixes the original issue? |
|
Backups and subordinate tests are failing, as expected (see #119 (comment)) I will retry the 2 remaining tests a few more times just in case. |
|
Been retrying the last test a few times. Despite not passing, the timeouts seem to be happening in different places, and there's nothing in the logs that suggests that they're caused by this PR. So I'm going to go ahead and merge. Thanks again @gboutry ! |
Replace getfqdn-based k8s hostname resolution with a canonical-name lookup built on getaddrinfo(AI_CANONNAME). Handle resolver failures, keep the trailing dot returned by DNS, and update the Kubernetes unit tests for the charm, provider, upgrade, and utility helpers. Fixes #137 Signed-off-by: Guillaume Boutry <guillaume.boutry@canonical.com>
Replace getfqdn-based k8s hostname resolution with a canonical-name lookup built on getaddrinfo(AI_CANONNAME). Handle resolver failures, keep the trailing dot returned by DNS, and update the Kubernetes unit tests for the charm, provider, upgrade, and utility helpers. Fixes #137 Signed-off-by: Guillaume Boutry <guillaume.boutry@canonical.com>
Replace getfqdn-based k8s hostname resolution with a canonical-name lookup built on getaddrinfo(AI_CANONNAME). Handle resolver failures, keep the trailing dot returned by DNS, and update the Kubernetes unit tests for the charm, provider, upgrade, and utility helpers. Fixes #137 Signed-off-by: Guillaume Boutry <guillaume.boutry@canonical.com> Co-authored-by: Guillaume Boutry <boutryguillaume1@gmail.com>
| for entry in info: | ||
| if canonname := entry[3]: | ||
| return canonname |
There was a problem hiding this comment.
I don't sure that logic is robust enough with different DNS engines for kubernetes.
There was a problem hiding this comment.
I think we should add the following function
import re
def is_srv_dns_record(s: str) -> bool:
"""Match pattern: pod-name.service-name.srv.some.domain.name."""
pattern = r'^[a-z0-9]([a-z0-9-]*[a-z0-9])?\.([a-z0-9]([a-z0-9-]*[a-z0-9])?\.)+srv(\.[a-z0-9]([a-z0-9-]*[a-z0-9])?){2,}\.?$'
return bool(re.match(pattern, s, re.IGNORECASE))
and use it here
| for entry in info: | |
| if canonname := entry[3]: | |
| return canonname | |
| for entry in info: | |
| if canonname := entry[3] and is_srv_dns_record(canonname): | |
| return canonname |
Issue
Fixes #137.
Solution
Replace
getfqdn-based Kubernetes hostname resolution with a canonical-namelookup built on
socket.getaddrinfo(..., AI_CANONNAME).The helper now scans resolver results for a canonical name, handles resolver
failures explicitly, preserves the trailing dot returned by DNS, and updates
the unit tests covering the charm, provider, upgrade, and utility paths.
Checklist